#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include <sys/stat.h>
#include <fcntl.h>

#include "relyer.h"


#define TTY1 "/home/sga/vscode/gitee/learn_linux/tty11"
#define TTY2 "/home/sga/vscode/gitee/learn_linux/tty12"
#define TTY3 "/home/sga/vscode/gitee/learn_linux/tty13"
#define TTY4 "/home/sga/vscode/gitee/learn_linux/tty14"


int main()
{
    int fd1, fd2, fd3, fd4;
    int job1, job2;
    fd1 = open(TTY1, O_RDWR);
    if (fd1 < 0)
    {
        perror("open()");
        exit(1);
    }

    fd2 = open(TTY2, O_RDWR | O_NONBLOCK);
    if (fd2 < 0)
    {
        perror("open()");
        exit(1);
    }

    fd3 = open(TTY3, O_RDWR);
    if (fd1 < 0)
    {
        perror("open()");
        exit(1);
    }

    fd4 = open(TTY4, O_RDWR | O_NONBLOCK);
    if (fd2 < 0)
    {
        perror("open()");
        exit(1);
    }

    job1 = rel_addjob(fd1, fd2);
    if (job1 < 0)
    {
        fprintf(stderr, "rel_addjob():%s", strerror(-job1));
    }

    job2 = rel_addjob(fd3, fd4);
    if (job2 < 0)
    {
        fprintf(stderr, "rel_addjob():%s", strerror(-job1));
    }

    while (1)
    {
        pause();
    }

    close(fd1);
    close(fd2);
    close(fd3);
    close(fd4);

    exit(0);
}